import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'
import frontRouter from './modules/front'
import powerRouter from './modules/power'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/error',
    name: 'Error',
    component: () => import('@/views/error-page'),
    hidden: true,
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index2'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'home', affix: true }
      }
    ]
  },
  {
    path: '/camera/display',
    name: 'CameraDisplay',
    hidden: true,
    component: () => import('@/views/control/cameraDisplay'),
    meta: {
      title: '视频展示',
      noCache: true
    }
  },
  {
    path: '/serv',
    name: 'Service',
    component: Layout,
    meta: {
      title: '后台管理',
      icon: 'conpany'
    },
    redirect: '/serv/list',
    children: [
      {
        path: "/serv/list",
        name: "Services",
        component: () => import("@/views/serv/index"),
        meta: {
          title: "报修列表",
        }
      }
    ]
  },
  // 暂留 start
  // {
  //   path: '/guide',
  //   component: Layout,
  //   redirect: '/guide/index',
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/guide/index'),
  //       name: 'Guide',
  //       meta: { title: 'Guide', icon: 'guide', noCache: true }
  //     }
  //   ]
  // },
  // {
  //   path: '/profile',
  //   component: Layout,
  //   redirect: '/profile/index',
  //   hidden: true,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/profile/index'),
  //       name: 'Profile',
  //       meta: { title: 'Profile', icon: 'user', noCache: true }
  //     }
  //   ]
  // },
  // end
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: '/user',
    name: 'User',
    component: Layout,
    meta: {
      title: '用户管理',
      icon: 'user1'
    },
    redirect: '/user/list',
    children: [
      {
        path: '/user/list',
        name: 'Users',
        component: () => import('@/views/user'),
        meta: {
          title: '用户列表',
        }
      },
      {
        path: '/user/role',
        name: 'UserRole',
        component: () => import('@/views/user/UserRole'),
        meta: {
          title: '角色列表',
        }
      },
      {
        path: '/user/privilege',
        name: 'Privilege',
        component: () => import('@/views/user/Privilege'),
        meta: {
          title: '权限列表',
        }
      },
      {
        path: '/user/resource',
        name: 'Resouce',
        component: () => import('@/views/user/Resouce'),
        meta: {
          title: '资源列表',
        }
      },
    ]
  },
  {
    path: '/workorder',
    name: 'WorkorderList',
    component: Layout,
    redirect: '/process/list',
    meta: {
      title: '工单管理',
      icon: 'work'
    },
    children: [
      {
        path: '/process/:id/node',
        name: 'ProcessNode',
        component: () => import('@/views/workorder/Node'),
        hidden: true,
        meta: {
          title: '设置节点'
        }
      },
      {
        path: '/process/list',
        name: 'Processes',
        component: () => import('@/views/workorder/ProcessList'),
        meta: {
          title: '流程列表'
        }
      },
      {
        path: '/workorders',
        name: 'Workorders',
        component: () => import('@/views/workorder/List'),
        meta: {
          title: '工单列表',
        }
      },
      {
        path: '/workorders/now',
        name: 'now',
        component: () => import('@/views/workorder/ReakOrder'),
        meta: {
          title: '实时工单',
        }
      },
      {
        path: '/workorders/History',
        name: 'History',
        component: () => import('@/views/workorder/History'),
        meta: {
          title: '历史工单',
        }
      },
      {
        path: '/workorders/mine',
        name: 'Mine',
        component: () => import('@/views/workorder/Mine'),
        meta: {
          title: '我的任务'
        }
      },
    ]
  },
  {
    path: '/device',
    name: 'Device',
    component: Layout,
    redirect: '/devices',
    meta: {
      title: '设备管理',
      icon: 'device-mng'
    },
    children: [
      {
        path: '/devices',
        name: 'Devices',
        component: () => import('@/views/device/List'),
        meta: {
          title: '设备台账',
        },
      },
      {
        path: '/device/:id/detail',
        name: 'DeviceDetail',
        hidden: true,
        component: () => import('@/views/device/detail'),
        meta: {
          title: '设备详情'
        }
      },
      {
        path: '/device/transfromer',
        name: 'Transformer',
        component: () => import('@/views/device/transformer'),
        meta: {
          title: '变压器系统'
        }
      },
      // {
      //   path: '/device/parts',
      //   name: 'Parts',
      //   component: () => import('@/views/Device/Parts'),
      //   meta: {
      //     title: '备品配件管理'
      //   }
      // },
      // {
      //   path: '/device/partrepo',
      //   name: 'PartRepo',
      //   component: () => import('@/views/Device/PartRepo'),
      //   meta: {
      //     title: '配件仓库台账'
      //   }
      // },
      // {
      //   path: '/device/outorder',
      //   name: 'OutOrder',
      //   component: () => import('@/views/Device/OutOrder'),
      //   meta: {
      //     title: '所有出库单'
      //   }
      // }
      {
        path: '/device/repairorder',
        name: 'RepairOrder',
        component: () => import('@/views/device/RepairOrder'),
        meta: {
          title: '设备维护日志',
        }
      }
    ]
  },
  {
    path: '/alarm',
    name: 'Alarm',
    component: Layout,
    meta: {
      title: '预警/告警管理',
      icon: 'alarm'
    },
    children: [
      {
        path: '/alarm/accident',
        name: 'AccidentAlarm',
        component: () => import('@/views/alarm/Accident'),
        meta: {
          title: '事故告警信息'
        }
      },
      {
        path: '/alarm/limit',
        name: 'LimitAlarm',
        component: () => import('@/views/alarm/Limit'),
        meta: {
          title: '越限告警信息'
        }
      },
      {
        path: '/alarm/exception',
        name: 'ExceptionAlarm',
        component: () => import('@/views/alarm/Exception'),
        meta: {
          title: '异常告警信息'
        }
      },
      {
        path: '/alarm/comm',
        name: 'CommAlarm',
        component: () => import('@/views/alarm/Comm'),
        meta: {
          title: '通信告警信息'
        }
      },
      {
        path: '/alarm/unbalance',
        name: 'UnbalanceAlarm',
        component: () => import('@/views/alarm/Unbalance'),
        meta: {
          title: '不平衡告警信息'
        }
      },
      {
        path: '/alarm/inhibition',
        name: 'InhibitionAlarm',
        component: () => import('@/views/alarm/Inhibition'),
        meta: {
          title: '告警抑制信息'
        }
      },
    ]
  },
  {
    path: '/data',
    name: 'Data',
    component: Layout,
    redirect: '/data/real',
    meta: {
      title: '数据查询',
      icon: 'data'
    },
    children: [
      {
        path: '/data/real',
        name: 'RealData',
        component: () => import('@/views/data/real'),
        meta: {
          title: '实时数据'
        }
      },
      {
        path: '/data/history',
        name: 'HistoryData',
        component: () => import('@/views/data/history'),
        meta: {
          title: '历史数据'
        }
      },
      {
        path: '/data/manual',
        name: 'Manual',
        component: () => import('@/views/data/manual'),
        meta: {
          title: '人工置数信息查询'
        }
      },
      {
        path: '/data/brand',
        name: 'Brand',
        component: () => import('@/views/data/brand'),
        meta: {
          title: '置标识牌信息查询'
        }
      },
      {
        path: '/data/all',
        name: 'AllData',
        component: () => import('@/views/data/AllData'),
        meta: {
          title: '电能集抄'
        }
      },
      {
        path: '/data/allhis',
        name: 'AllDataHis',
        component: () => import('@/views/data/AllDataHis'),
        meta: {
          title: '电能历史数据'
        }
      },
      {
        path: '/data/monthly',
        name: 'DataMonthly',
        component: () => import('@/views/data/monthly'),
        meta: {
          title: '月报列表'
        }
      }
    ]
  },
  {
    path: '/control',
    name: 'Control',
    component: Layout,
    redirect: '/control/svg',
    meta: {
      title: '实时运行监控',
      icon: 'control'
    },
    children: [
      {
        path: '/control/one',
        name: 'SvgOne',
        component: () => import('@/views/control/one'),
        meta: {
          title: '一次接线图'
        }
      },
      {
        path: '/control/dev',
        name: 'SvgDev',
        component: () => import('@/views/control/dev'),
        meta: {
          title: '设备运行图'
        }
      },
      {
        path: '/control/comm',
        name: 'SvgComm',
        component: () => import('@/views/control/comm'),
        meta: {
          title: '通讯检测图'
        }
      },
      {
        path: '/control/camera',
        name: 'Camera',
        component: () => import('@/views/control/camera'),
        meta: {
          title: '视频监控'
        }
      },
    ]
  },
  {
    path: '/company',
    name: 'Company',
    component: Layout,
    meta: {
      title: '公司管理',
      icon: 'conpany'
    },
    redirect: '/company/list',
    children: [
      {
        path: '/company/list',
        name: 'CompanyList',
        component: () => import('@/views/company'),
        meta: {
          title: '公司列表',
        }
      },
      // {
      //   path: '/company/staff',
      //   name: 'Staff',
      //   component: () => import('@/views/company/staff'),
      //   meta: {
      //     title: '员工列表',
      //   }
      // },
      {
        path: '/company/station',
        name: 'Station',
        component: () => import('@/views/company/station'),
        meta: {
          title: '站点列表'
        }
      },
      {
        path: '/company/contract',
        name: 'Contract',
        component: () => import('@/views/company/contract'),
        meta: {
          title: '合同列表'
        }
      },
      {
        path: '/company/contract/:id/maintain',
        name: 'Maintain',
        hidden: true,
        component: () => import('@/views/company/maintain'),
        meta: {
          title: '维护项目',
          noCache: true,
        }
      },
      {
        path: '/company/map',
        name: 'StationMap',
        component: () => import('@/views/company/stationMap'),
        meta: {
          title: '站点地图'
        }
      }
    ]
  },
  frontRouter,
  ...powerRouter,
  // {
  //   path: '/permission',
  //   component: Layout,
  //   redirect: '/permission/page',
  //   alwaysShow: true, // will always show the root menu
  //   name: 'Permission',
  //   meta: {
  //     title: '权限',
  //     icon: 'lock',
  //     roles: ['admin', 'editor'] // you can set roles in root nav
  //   },
  //   children: [
  //     {
  //       path: 'page',
  //       component: () => import('@/views/permission/page'),
  //       name: 'PagePermission',
  //       meta: {
  //         title: 'Page Permission',
  //         roles: ['admin'] // or you can only set roles in sub nav
  //       }
  //     },
  //     {
  //       path: 'directive',
  //       component: () => import('@/views/permission/directive'),
  //       name: 'DirectivePermission',
  //       meta: {
  //         title: 'Directive Permission'
  //         // if do not set roles, means: this page does not require permission
  //       }
  //     },
  //     {
  //       path: 'role',
  //       component: () => import('@/views/permission/role'),
  //       name: 'RolePermission',
  //       meta: {
  //         title: 'Role Permission',
  //         roles: ['admin']
  //       }
  //     }
  //   ]
  // },

  // {
  //   path: '/icon',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/icons/index'),
  //       name: 'Icons',
  //       meta: { title: 'Icons', icon: 'icon', noCache: true }
  //     }
  //   ]
  // },

  // /** when your routing map is too long, you can split it into small modules **/
  // componentsRouter,
  // chartsRouter,
  // nestedRouter,
  // tableRouter,

  // {
  //   path: '/example',
  //   component: Layout,
  //   redirect: '/example/list',
  //   name: 'Example',
  //   meta: {
  //     title: 'Example',
  //     icon: 'example'
  //   },
  //   children: [
  //     {
  //       path: 'create',
  //       component: () => import('@/views/example/create'),
  //       name: 'CreateArticle',
  //       meta: { title: 'Create Article', icon: 'edit' }
  //     },
  //     {
  //       path: 'edit/:id(\\d+)',
  //       component: () => import('@/views/example/edit'),
  //       name: 'EditArticle',
  //       meta: { title: 'Edit Article', noCache: true, activeMenu: '/example/list' },
  //       hidden: true
  //     },
  //     {
  //       path: 'list',
  //       component: () => import('@/views/example/list'),
  //       name: 'ArticleList',
  //       meta: { title: 'Article List', icon: 'list' }
  //     }
  //   ]
  // },

  // {
  //   path: '/tab',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/tab/index'),
  //       name: 'Tab',
  //       meta: { title: 'Tab', icon: 'tab' }
  //     }
  //   ]
  // },

  // {
  //   path: '/error',
  //   component: Layout,
  //   redirect: 'noRedirect',
  //   name: 'ErrorPages',
  //   meta: {
  //     title: 'Error Pages',
  //     icon: '404'
  //   },
  //   children: [
  //     {
  //       path: '401',
  //       component: () => import('@/views/error-page/401'),
  //       name: 'Page401',
  //       meta: { title: '401', noCache: true }
  //     },
  //     {
  //       path: '404',
  //       component: () => import('@/views/error-page/404'),
  //       name: 'Page404',
  //       meta: { title: '404', noCache: true }
  //     }
  //   ]
  // },

  // {
  //   path: '/error-log',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'log',
  //       component: () => import('@/views/error-log/index'),
  //       name: 'ErrorLog',
  //       meta: { title: 'Error Log', icon: 'bug' }
  //     }
  //   ]
  // },

  // {
  //   path: '/excel',
  //   component: Layout,
  //   redirect: '/excel/export-excel',
  //   name: 'Excel',
  //   meta: {
  //     title: 'Excel',
  //     icon: 'excel'
  //   },
  //   children: [
  //     {
  //       path: 'export-excel',
  //       component: () => import('@/views/excel/export-excel'),
  //       name: 'ExportExcel',
  //       meta: { title: 'Export Excel' }
  //     },
  //     {
  //       path: 'export-selected-excel',
  //       component: () => import('@/views/excel/select-excel'),
  //       name: 'SelectExcel',
  //       meta: { title: 'Export Selected' }
  //     },
  //     {
  //       path: 'export-merge-header',
  //       component: () => import('@/views/excel/merge-header'),
  //       name: 'MergeHeader',
  //       meta: { title: 'Merge Header' }
  //     },
  //     {
  //       path: 'upload-excel',
  //       component: () => import('@/views/excel/upload-excel'),
  //       name: 'UploadExcel',
  //       meta: { title: 'Upload Excel' }
  //     }
  //   ]
  // },

  // {
  //   path: '/zip',
  //   component: Layout,
  //   redirect: '/zip/download',
  //   alwaysShow: true,
  //   name: 'Zip',
  //   meta: { title: 'Zip', icon: 'zip' },
  //   children: [
  //     {
  //       path: 'download',
  //       component: () => import('@/views/zip/index'),
  //       name: 'ExportZip',
  //       meta: { title: 'Export Zip' }
  //     }
  //   ]
  // },

  // {
  //   path: '/pdf',
  //   component: Layout,
  //   redirect: '/pdf/index',
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/pdf/index'),
  //       name: 'PDF',
  //       meta: { title: 'PDF', icon: 'pdf' }
  //     }
  //   ]
  // },
  // {
  //   path: '/pdf/download',
  //   component: () => import('@/views/pdf/download'),
  //   hidden: true
  // },

  // {
  //   path: '/theme',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/theme/index'),
  //       name: 'Theme',
  //       meta: { title: 'Theme', icon: 'theme' }
  //     }
  //   ]
  // },

  // {
  //   path: '/clipboard',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/clipboard/index'),
  //       name: 'ClipboardDemo',
  //       meta: { title: 'Clipboard', icon: 'clipboard' }
  //     }
  //   ]
  // },

  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://github.com/PanJiaChen/vue-element-admin',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', name: 404, hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
